import style from './index.module.scss'

async function Index({ list, type }) {
  const [trade, id] = type?.split('_')
  let currentTrade: number | null = null
  let currentJob: number | null = null
  let jobList: any = []
  if (trade === 'list') {
    for (let i = 0; i < list.length; i++) {
      jobList.push(...list[i].children.slice(0, 4))
    }
  }

  if (trade === 'trade') {
    currentTrade = +id
    jobList = list.find(t => t.id === +id)?.children || []
  }
  if (trade === 'job') {
    for (let i = 0; i < list.length; i++) {
      const item = list[i].children.find(t => t.id === +id)
      if (item) {
        currentTrade = item.parentId
        currentJob = +id
        jobList = list.find(t => t.id === item.parentId)?.children || []
        break
      }
    }
  }
  return (<div className={style.jobTitle}>
    <div className={style.jobContainer}>
      <div className={style.title}>
      行业
      </div>
      <ul className={style.jobTitleContent}>
        {
          list.map((item) => {
            return <li key={item.id}><a href={`/cv/trade_${item.id}/1`} className={currentTrade === item.id ? style.active : ''}>{item.name}</a></li>
          })
        }
      </ul>
    </div>
    <div className={style.jobContainer}>
      <div className={style.title}>
      职位
      </div>
      <ul className={style.jobTitleContent}>
        {
          jobList.map((item) => {
            return <li key={item.id}><a href={`/cv/job_${item.id}/1`} className={currentJob === item.id ? style.active : ''}>{item.name}</a></li>
          })
        }
      </ul>
    </div>

  </div>);
}

export default Index;
